package way.learning.zz;

import java.util.concurrent.Future;

/**
 * This class represents a DirectoryPoller instance that is about to start.
 * Use this class to:
 *  1:Ask if the DirectoryPoller has started or not.</li>
 *  2:Retrieve the DirectoryPoller instance after it has been started.
 *
 */
public final class DirectoryPollerFuture {

    //Future接口
    private final Future<DirectoryPoller> future;

    //构造函数 Future为接口类型
    DirectoryPollerFuture(Future<DirectoryPoller> future) {
        this.future = future;
    }

    /**
     * This method will block until all BeforeStartEvent events has been fired (and processed by all listeners.)
     * 
     * return a started DirectoryPoller instance.
     */
    public DirectoryPoller get() {
        try {
            return future.get();
        } catch (Exception e) {
            String message = "get() method threw exception!";
            throw new UnsupportedOperationException(message, e);
        }
    }

    /**
     * @return true if {@link DirectoryPoller} has started, otherwise false.
     */
    public boolean isStarted() {
        return future.isDone();
    }

}
